package com.blockmeta.bbs.businesslibrary.pojo.websocket;

import org.json.JSONObject;

/**
 * Created by bytom on 2018/4/3.
 */

public class POJOCache {
    private boolean m_bUseCache = false;
    CompressMode m_compressModeCache = null;
    byte[] m_byBytesCache = null;
    String m_sJsonStringCache = null;
    JSONObject m_jsonCache = null;
    byte[] m_msgPackCache = null;

    public POJOCache(boolean bUseCache) {
        this.m_bUseCache = bUseCache;
    }

    public boolean isUseCache() {
        return this.m_bUseCache;
    }

    public void setNotUseCache() {
        this.m_bUseCache = false;
        this.clearCache();
    }

    public void clearCache() {
        this.m_byBytesCache = null;
        this.m_sJsonStringCache = null;
        this.m_compressModeCache = null;
        this.m_jsonCache = null;
        this.m_msgPackCache = null;
    }

    public void setUseCache() {
        this.m_bUseCache = true;
    }

    public byte[] getBytesCache(CompressMode compressMode) {
        return this.m_bUseCache && compressMode == this.m_compressModeCache && compressMode != null?this.m_byBytesCache:null;
    }

    public void setBytesCache(CompressMode compressMode, byte[] byCache) {
        if(this.m_bUseCache) {
            this.m_byBytesCache = byCache;
            this.m_compressModeCache = compressMode;
        }

    }

    public String getJsonString() {
        return this.m_bUseCache?this.m_sJsonStringCache:null;
    }

    public void setJsonStringCache(String sJsonString) {
        if(this.m_bUseCache) {
            this.m_sJsonStringCache = sJsonString;
        }

    }

    public JSONObject getJsonObject() {
        return this.m_bUseCache?this.m_jsonCache:null;
    }

    public byte[] getMsgPackObject() {
        return this.m_bUseCache?this.m_msgPackCache:null;
    }

    public void setJsonObjectCache(JSONObject json) {
        if(this.m_bUseCache) {
            this.m_jsonCache = json;
        }

    }

    public void setMsgPackObjectCache(byte[] msgPack) {
        if(this.m_bUseCache) {
            this.m_msgPackCache = msgPack;
        }

    }
}
